<?php

class CCoreLabsWebMailAttachment
{
	const OBJECT_ERROR_CODE = 2000;

	public $MimeIndex;
	public $FileName;
	public $MimeType;
	public $Size;
	public $Cid;

	private $_mFormationCallback = null;

	/**
	 * @param string $sMimeIndex
	 * @param string $sFileName
	 * @param string $sMimeType
	 * @param int $iSize
	 * @param string $sContentTransferEncoding
	 * @param string $sCid
	 * @return CCoreLabsWebMailAttachment
	 */
	public function __construct($sMimeIndex, $sFileName, $sMimeType, $iSize, $sContentTransferEncoding, $sCid)
	{
		$this->MimeIndex = $sMimeIndex;
		$this->FileName = $sFileName;
		$this->MimeType = $sMimeType;
		$this->Size = $iSize;
		$this->ContentTransferEncoding = $sContentTransferEncoding;
		$this->Cid = $sCid;
	}

	public function InitFormationCallback($mFormationCallback)
	{
		$this->_mFormationCallback = $mFormationCallback;
	}

	public function CallbackAttachmentStreamParse($rStream, $sLiteralAtomUpperCase)
	{
		if (null !== $this->_mFormationCallback)
		{
			$sInlineDecodeFunctionName = CCoreMimeUtils::GetInlineDecodeFunctionName(
				$this->ContentTransferEncoding);
			
			$rAttachmentStream = CCoreMimeStreamWrapper::CreateBinaryStream(
				$rStream, $sInlineDecodeFunctionName);
			
			call_user_func($this->_mFormationCallback, $this, $rAttachmentStream);
		}
	}
}